package com.uenpay.im.ui.old.activity.publicnumber;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;


/**
 * @author SL
 * @created 2016-1-8 上午10:27:35
 * @copyRight http://www.qiyunxin.com
 * @function 关注公众号
 */
public class FollowPublicNumberInvokeItem extends BaseHttpInvokeItem {
	public class FollowPublicNumberInvokeItemResult extends HttpInvokeResult {
		public ArrayList<PublicNumEntity> arrayList = new ArrayList<PublicNumEntity>();
	}

	public FollowPublicNumberInvokeItemResult getOutput() {
		return (FollowPublicNumberInvokeItemResult) GetResultObject();
	}

	/**
	 * 
	 * @param type
	 *            1:取消关注
	 * @param publicnoid
	 */
	public FollowPublicNumberInvokeItem(int type, String publicnoid) {
		String url = "";
		if (type == 0) {
			url = APIConfiguration.getBaseUrl()
					+ "PublicNo/PublicNo/followPublicNo?publicnoid=" + publicnoid + "&"
					+ APIConfiguration.getCustIdAndToken();
		} else {
			url = APIConfiguration.getBaseUrl()
					+ "PublicNoPublicNo/cancelFollowFublicNo?publicnoid=" + publicnoid
					+ "&" + APIConfiguration.getCustIdAndToken();
		}
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		FollowPublicNumberInvokeItemResult result = new FollowPublicNumberInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		if (result.status != 0) {
			return result;
		}
		return result;
	}
}
